<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
</head>

<body>
	<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
	<!-- <script src="index.js"></script> -->
	<script>
		const jsonp = ({ url, params, callbackName }) => {
			const generateUrl = () => {
				let dataSrc = '';
				for (let key in params) {
					if (Object.prototype.hasOwnProperty.call(params, key)) {
						dataSrc += `${key}=${params[key]}&`;
					}
				}
				dataSrc += `callback=${callbackName}`;
				return `${url}?${dataSrc}`;
			}
			return new Promise((resolve, reject) => {
				const scriptEle = document.createElement('script');
				scriptEle.src = generateUrl();
				document.body.appendChild(scriptEle);
				window[callbackName] = data => {
					resolve(data);
					// document.removeChild(scriptEle);
				}
			})
		}

		jsonp({ 
			url: "index.js", 
			params: { 
				username: "admin", 
				password: "123456" 
			}, 
			callbackName: "fun1234" 
		}).then((res) => {
			// let result = fun1234();
			console.log(res)
		})
	</script>
</body>

</html>